import java.util.Arrays;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        /**
         * 冒泡排序
         */
        int[] arr=new int[]{3,2,1,0};
        for (int i = 0; i < arr.length-1; i++) {//比较的是趟数
            for (int j = 0; j < arr.length-1-i; j++) {//比较的是每个数比较的次数
                if(arr[j]>arr[j+1]){
                    int tmp=arr[j+1];
                    arr[j+1]=arr[j];
                    arr[j]=tmp;
                }
            }
        }
        for (int x:arr
             ) {
            System.out.println(x);
        }
    }
    public static void main4(String[] args) {
        /**
         * 二分查找,
         */
        int[] arr=new int[]{1,2,3,4,5,6,7};
        int left=0;
        int right=arr.length;
        int met=(left+right)/2;
        Scanner scanner=new Scanner(System.in);
        int key=scanner.nextByte();
        while (left<=right){
            if(arr[met]==key){
                System.out.println(met);
                break;
            }else if(arr[met]<key){
                left=met+1;
                met=(left+right)/2;
            }else{
                right=met-1;
                met=(right+left)/2;
            }
        }
//        Arrays.sort(arr);//数组排序
//        System.out.println(Arrays.binarySearch(arr,3));//查找元素下表
    }
    /**
     * 求数组平均数
     * @param
     */
    public static double avg(int[] arr){
        int tmp=0;
        for (int x:arr) {
            tmp+=x;
        }
        return  tmp*1.0/arr.length;
    }
    public static void main3(String[] args) {
        int [] arr=new int[]{1,2,3,4};
        double a= avg(arr);
        System.out.println(a);

    }
    public static void main2(String[] args) {
        int[] arr=new int[]{1,2,3,4,5};
//        int[] copy= Arrays.copyOf(arr,arr.length);
        int[] copy= Arrays.copyOfRange(arr,0,arr.length);

        System.out.println(Arrays.toString(copy));
    }
    public static String mytoString(int[] arr){
        String ret="[";
        for (int i = 0; i < arr.length; i++) {
            ret +=arr[i];
            if(i!=arr.length-1){
                ret+=",";
            }

        }
        ret+="]";
        return ret;
    }
    public static void main1(String[] args) {
        /**
         * 重写toString方法
         */

        int[] arr= new int[]{1,2,3,4};

       String str= mytoString(arr);
        System.out.println(str);
    }
}
